package thesystem;

import org.springframework.util.StopWatch;
import org.testng.annotations.Test;

/**
 * @author
 */
public class SpringStopWatch {

    /**
     * spring的秒表可以打印统计信息，Google的秒表没有这个功能
     *
     */
    @Test
    private void t1() throws InterruptedException {
        StopWatch stopWatch = new StopWatch();

        stopWatch.start("test 1");
        Thread.sleep(200);
        stopWatch.stop();

        stopWatch.start("test 2");
        Thread.sleep(500);
        stopWatch.stop();

        System.out.println(stopWatch.prettyPrint());
    }

    @Test
    private void t2() throws InterruptedException {
        StopWatch stopWatch = new StopWatch("test one");

        // 这个名字不会打印出来
        stopWatch.start("test 1");
        Thread.sleep(700);
        stopWatch.stop();
        // 打印一个秒表的简要信息
        System.out.println(stopWatch.shortSummary());
    }

    /**
     *
     */
    @Test
    private void t3() throws InterruptedException {
        // 这个名字是秒表的id
        StopWatch stopWatch = new StopWatch("test one");
        stopWatch.start("test 0");
        Thread.sleep(100);
        stopWatch.stop();

//        这个名字是秒表的一个任务
        stopWatch.start("test 1");
        Thread.sleep(100);
        stopWatch.stop();

        stopWatch.start("test 2");
        Thread.sleep(100);
        stopWatch.stop();

        System.out.println(stopWatch.prettyPrint());
    }

    @Test
    private void t5() throws InterruptedException {
        StopWatch stopWatch = new StopWatch();

        stopWatch.start("task 1");
        Thread.sleep(100);
        stopWatch.stop();

        stopWatch.start("task 2");
        Thread.sleep(100);
        stopWatch.stop();

        stopWatch.start("task 3");
        Thread.sleep(100);
        stopWatch.stop();

        System.out.println(stopWatch.getTaskCount());

    }





}
